package com.jiuyue.movehouse.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jiuyue.movehouse.annotion.JsonFilter;
import com.jiuyue.movehouse.annotion.PageInfo;
import com.jiuyue.movehouse.entity.User;
import com.jiuyue.movehouse.service.UserService;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author yourFather
 * @since 2022-02-11
 */
@RestController
@RequestMapping("/user")
@AllArgsConstructor
public class UserController {

    private UserService userService;

    @JsonFilter(excludes = {"password"})
    @PostMapping("login")
    public User Login(@RequestBody @Validated(User.Login.class) User user) {
        return userService.Login(user);
    }

    @JsonFilter(excludes = {"password"})
    @PostMapping("register")
    public User register(@RequestBody @Validated(User.Register.class) User user) {
        return userService.Register(user);
    }

    @JsonFilter(excludes = {"password"})
    @GetMapping("getUserList")
    public Page<User> getUserList(@PageInfo Page page, User user) {
        return userService.getUserList(page,user);
    }

    @PostMapping("resetPassword/{userId}/{password}")
    public void resetPassword(@PathVariable Long userId,@PathVariable String password) {
        userService.resetPassword(userId,password);
    }

    @PostMapping("updateType/{userId}/{type}")
    public void updateType(@PathVariable Long userId,@PathVariable String type) {
        userService.updateType(userId,type);
    }

    @DeleteMapping("deleteUser/{userId}")
    public void deleteUser(@PathVariable Long userId) {
        userService.deleteUser(userId);
    }

}

